package com.harbintransport.backend;

import com.harbintransport.backend.model.OdAnalysis;
import com.harbintransport.backend.repository.BusRushHourTrafficRepository;
import com.harbintransport.backend.repository.OdAnalysisRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;
import java.util.List;

@SpringBootApplication
public class HarbinTransportBackendApplication {

    public static void main(String[] args) {
        SpringApplication.run(HarbinTransportBackendApplication.class, args);
    }

    @Bean
    public CommandLineRunner initDatabase(OdAnalysisRepository repository) {
        return args -> {
            if (repository.count() == 0) {
                // 编造更丰富、更真实的OD数据并存入数据库
                List<OdAnalysis> odData = Arrays.asList(
                        // 主要始发站
                        new OdAnalysis("黑龙江大学", "秋林公司", 12000),
                        new OdAnalysis("黑龙江大学", "铁路局", 8000),
                        new OdAnalysis("科技创新城", "闽江路", 9500),
                        new OdAnalysis("科技创新城", "防洪纪念塔", 6000),

                        // 中间换乘/商业区
                        new OdAnalysis("邮政街", "秋林公司", 5000),
                        new OdAnalysis("邮政街", "铁路局", 3000),
                        new OdAnalysis("防洪纪念塔", "道里客运站", 4500),

                        // 汇集到主要终点站
                        new OdAnalysis("秋林公司", "哈西客站东广场", 15000),
                        new OdAnalysis("铁路局", "哈西客站东广场", 10000),
                        new OdAnalysis("闽江路", "道里客运站", 8000),
                        new OdAnalysis("道里客运站", "哈西客站东广场", 11000));
                repository.saveAll(odData);
            }
        };
    }
}